package com.ruoyi.standingbook.v2toilet.bill;

import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.ruoyi.standingbook.v2toilet.domain.bo.V2ToiletBillBo;
import com.ruoyi.standingbook.v2toilet.bill.BillFlow;
import com.ruoyi.standingbook.v2toilet.enums.ItemStatusEnum;

import java.util.Date;
import java.util.Objects;

public class BillFlowUtil {
    public static V2ToiletBillBo setFlow(V2ToiletBillBo bo) {
        JSONObject obj = JSONUtil.parseObj(bo.getFlowData(), true);
        obj.setDateFormat("yyyy-MM-dd HH:mm:ss");
        ItemStatusEnum billStatus = ItemStatusEnum.getByIntCode(bo.getStatus());
        BillFlow flow;
        String index = "";
        //        这个地方和状态没有关系
        //        1.是异常，
        //        2待处理（等智检发结果，同时知道将是谁在处理），
        //        3 完成 这时的人是 2中一个
        Date date = new Date();//Objects.isNull(bo.getCreateTime()) ? new Date() : bo.getCreateTime();
        String time = DateUtil.format(date, "yyyy-MM-dd HH:mm:ss");
        switch (billStatus) {
            case SAVED:
            case ERR:
                //obj.set(BillStatusEnum.COMMIT.strCode, new BillFlow(bo.getCurrUser(), new Date(), true));
                obj.set("1", new BillFlow(bo.getCurrUser(), time, true));
                obj.set("2", new BillFlow("", "", false));
                obj.set("3", new BillFlow("", "", false));
                break;
            case OK://全正常
                obj.set("1", new BillFlow(bo.getCurrUser(), time, true));
                obj.set("2", new BillFlow(bo.getCurrUser(), time, true));
                obj.set("3", new BillFlow(bo.getCurrUser(), time, true));
                break;
            case ERR_TO_OK://智检返回
                //包含1,2
                obj.set("3", new BillFlow(bo.getCurrUser(), time, true));
                break;

            case COMMIT:
                obj.set("2", new BillFlow(bo.getCurrUser(), time, true));
                obj.set("3", new BillFlow("", "", false));
                break;
            default:
                obj.set("1", new BillFlow("", "", false));
                obj.set("2", new BillFlow("", "", false));
                obj.set("3", new BillFlow("", "", false));
                break;
        }
        bo.setFlowData(JSONUtil.toJsonStr(obj));
        return bo;


    }

}
